package com.fyzk.raceview.ssqdlt;

import java.util.ArrayList;
import java.util.List;

import android.util.Log;

import com.fyzk.raceview.BetNum;
import com.fyzk.raceview.RaceShuZiCaiView;

/**
 * 大乐透
 * 
 * @author fxs
 * 
 */
public class Detail_SSQandDLT extends RaceShuZiCaiView {

	@Override
	protected void splitContent(String content, String prizeNum) {
		String prize_hong = "";
		String prize_lan = "";
		if (prizeNum != null && !prizeNum.equals("") && prizeNum.contains("|")) {
			prize_hong = prizeNum.split("\\|")[0];
			prize_lan = prizeNum.split("\\|")[1];
		}

		String[] itemContents;
		if (content.contains("!")) {
			itemContents = content.split("!");
		} else {
			itemContents = new String[] { content };
		}

		for (int i = 0; i < itemContents.length; i++) {
			List<BetNum> betNums1 = new ArrayList<BetNum>();
			String itemContent = itemContents[i];// 100101-01,02,03,04,05,06|07^01,02,03,04,05,06|07^01,02,03,04,05,06|07^
			if (itemContent.contains("-")) {
				String wcode = itemContent.split("-")[0];// 100101
				String betContents = itemContent.split("-")[1];// 01#06,07,08,09,10,11,12,13,14,15|07^01,02,03,04,05,06|07^01,02,03,04,05,06|07^

				lotteryIds.add(wcode.substring(0, 4));
				wcodes.add(wcode);

				String[] betCs;
				if (betContents.contains("^")) {
					betCs = betContents.split("\\^");
					for (int j = 0; j < betCs.length; j++) {
						String betC = betCs[j];// 01#06,07,08,09,10,11,12,13,14,15|07
						Log.e("============", "---- betC: " + betC);
						if (betC.contains("|")) {
							String h_and_dC = betC.split("\\|")[0];// 01#06,07,08,09,10,11,12,13,14,15
							String l_and_dC = betC.split("\\|")[1];// 07,09(单式蓝球只有一个号)
							String hongC = "";
							String hong_danC = "";
							String lanC = "";
							String lan_danC = "";

							if (h_and_dC.contains("#")) {

								hong_danC = h_and_dC.split("#")[0];
								hongC = h_and_dC.split("#")[1];

								betNums1.add(new BetNum("(",
										BetNum.TYPE_KH_LEFT, false));// 添加左括号
								betNums1.addAll(getBetNums(hong_danC,
										BetNum.TYPE_YELLOW, prize_hong));
								betNums1.add(new BetNum(")",
										BetNum.TYPE_KH_RIGHT, false));// 添加右括号
							} else {
								hongC = h_and_dC;
							}
							betNums1.addAll(getBetNums(hongC, BetNum.TYPE_RED,
									prize_hong));

							betNums1.add(new BetNum("|", BetNum.TYPE_LINE,
									false));
							if (l_and_dC.contains("#")) {
								lan_danC = l_and_dC.split("#")[0];
								lanC = l_and_dC.split("#")[1];

								betNums1.add(new BetNum("(",
										BetNum.TYPE_KH_LEFT, false));// 添加左括号
								betNums1.addAll(getBetNums(lan_danC,
										BetNum.TYPE_YELLOW, prize_lan));
								betNums1.add(new BetNum(")",
										BetNum.TYPE_KH_RIGHT, false));// 添加右括号

							} else {
								lanC = l_and_dC;
							}
							betNums1.addAll(getBetNums(lanC, BetNum.TYPE_BULE,
									prize_lan));

						}
						betNums1.add(new BetNum(" - ", BetNum.TYPE_LINE,
								false));
					}
				}
				try {
					betNums1.remove(betNums1.size()-1);
				} catch (Exception e) {
					// TODO: handle exception
				}
				
				betNums.add(betNums1);
			}

		}

	}

	protected void splitContent(String content, String prizeNum, int codeFilter) {

		if (codeFilter == 1) {
			String prize_hong = "";
			String prize_lan = "";
			if (prizeNum != null && !prizeNum.equals("")
					&& prizeNum.contains("|")) {
				prize_hong = prizeNum.split("\\|")[0];
				prize_lan = prizeNum.split("\\|")[1];
			}
			String[] itemContents;
			if (content.contains("!")) {
				itemContents = content.split("!");
			} else {
				itemContents = new String[] { content };
			}

			for (int i = 0; i < itemContents.length; i++) {
				String itemContent = itemContents[i];
				if (itemContent.contains("-")) {
					String wcode = itemContent.split("-")[0];
					String betContents = itemContent.split("-")[1];
					String[] betCs;
					if (betContents.contains("^")) {
						betCs = betContents.split("\\^");
						for (int j = 0; j < betCs.length; j++) {
							lotteryIds.add(wcode.substring(0, 4));
							wcodes.add(wcode);
							List<BetNum> betNums1 = new ArrayList<BetNum>();
							String betC = betCs[j];
							if (betC.contains("|")) {
								String hongC = betC.split("\\|")[0];
								String lanC = betC.split("\\|")[1];
								betNums1.addAll(getBetNums(hongC,
										BetNum.TYPE_RED, prize_hong));
								betNums1.add(new BetNum("|", BetNum.TYPE_LINE,
										false));
								betNums1.addAll(getBetNums(lanC,
										BetNum.TYPE_BULE, prize_lan));
							}
							betNums.add(betNums1);
						}
					}
				}

			}

		} else {
			splitContent(content, prizeNum);
		}

	}

	private List<BetNum> getBetNums(String numConstent, int type,
			String prizeNum) {
		List<BetNum> betNums1 = new ArrayList<BetNum>();
		if (numConstent.contains(",")) {
			String[] hongCs = numConstent.split(",");
			for (int k = 0; k < hongCs.length; k++) {
				String hong = hongCs[k];
				betNums1.add(new BetNum(hong, type, prizeNum.contains(hong)));// 添加红球
			}
		} else {
			betNums1.add(new BetNum(numConstent, type, prizeNum
					.contains(numConstent)));// 添加红球
		}
		return betNums1;
	}

}
